<template>
  <div style="background:#EBEEF5;">
    <el-row style="margin: 12px 0px 12px 20px;">
      <el-col :span="24">
    <el-breadcrumb separator="/">
        <el-breadcrumb-item v-for="item in routerList" v-bind:key="item.path" :to="{ path: item.path }">{{ item.meta.name }}</el-breadcrumb-item>
    </el-breadcrumb>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'CBreadcrumb',
  data () {
    return {
      routerList: []
    }
  },
  created () {
    this.getBreadcrumb()
  },
  watch: {
    $route () {
      this.getBreadcrumb()
    }
  },
  methods: {
    getBreadcrumb () {
      let matched = this.$route.matched.filter(item => item.meta && item.meta.name)
      if (matched) {
        matched = [{ path: '/', meta: { name: '首页' } }].concat(matched)
      }
      console.log(matched)
      this.routerList = matched
    }
  }

}
</script>
